home *** CD-ROM | disk | FTP | other *** search
- Path: access4.digex.net!not-for-mail
- From: ell@access4.digex.net (Ell)
- Newsgroups: comp.lang.c++
- Subject: Re: Pure Virtual Destructor Question
- Date: 10 Feb 1996 18:57:40 GMT
- Organization: The Universe
- Message-ID: <4fipr4$f71@news4.digex.net>
- References: <4fas7a$7ns@comet2.magicnet.net>
- NNTP-Posting-Host: access4.digex.net
- X-Newsreader: TIN [UNIX 1.3 950824BETA PL0]
-
- Jody Hagins (gamecox@magicnet.magicnet.net) wrote:
- : Assume a class Foo s.t.
- :
- : class Foo
- : {
- : public:
- : virtual ~Foo() = 0;
- : };
- :
- : inline Foo::~Foo()
- : {
- : // do some destructor stuff
- : }
- :
- : This is correct, and compiles fine.
-
- Right.
-
- : However, I get a warning:
- : "foo.h", : warning: please provide an out-of-line definition:
- : Foo::~Foo() {};
- : which is needed by derived classes
-
- I don't get warning this with VC++ 1.5.
-
- : Even when I make it non inline (in foo.C) I still get it. The only way
- : I can think of to get around the problem is to do it right in the declaration
- : itself. However, the compiler barks at both
- :
- : class Foo
- : {
- : public:
- : virtual ~Foo() { /* do some stuff */ } = 0;
- : };
- :
- : and
- :
- : class Foo
- : {
- : public:
- : virtual ~Foo() = 0 { /* do some stuff */ }
- : };
-
- Pretty sure you can not declare a pure virtual function within a class and
- supply a definition for it _within_ the class it is declared in. So while
- a pure virtual may have a definition, the definition itself must be
- physically outside the class.
-
- The nice thing about this is that you can keep the class from being
- instantiated, simply by using a pure virtual dtor. Yet the dtor may have
- the same functionality as a non-pure virtual dtor.
-
- How about that folks? ;)
-
- Elliott
-